const ESCAPE: u32 = 27;
use std::path::PathBuf;

use calamine::{Reader, Xlsx, open_workbook};

pub fn xls2txt(file: PathBuf, xlsx_start: Option<usize>) {
    let c = char::from_u32(ESCAPE).unwrap();

    let mut workbook: Xlsx<_> = open_workbook(&file).expect("Cannot open file");
    let xlsx_start_with = xlsx_start.unwrap_or(0);
    for sheet in workbook.sheet_names() {
        let range = workbook.worksheet_range(&sheet).unwrap();
        for (rindex, row) in range.rows().enumerate() {
            if rindex <= xlsx_start_with {
                continue;
            }
            let mut row_values = String::new();
            for item in row {
                row_values.push_str(&item.to_string());
                row_values.push(c);
            }
            println!("{}", row_values);
        }
    }
}
